const express = require("express");
const app = express();
const port = 3000;

const userRouter = require("./routes/module-user");
const fooRouter = require("./routes/module-foo");
// app.use("/", userRouter, fooRouter);
app.use(userRouter, fooRouter);
// app.get("/", userRouter, fooRouter);

// const innerRouter = express.Router();
// innerRouter.use("/user", userRouter);
// innerRouter.use("/foo", fooRouter);
// app.use(innerRouter);

// const router = express.Router();
// router.get(
//   "/user/:id",
//   (req, res, next) => {
//     // if the user ID is 0, skip to the next router
//     if (req.params.id === "0") next("route");
//     // otherwise pass control to the next middleware function in this stack
//     else next();
//   },
//   (req, res, next) => {
//     // render a regular page
//     // res.render("regular");
//     res.send("regular page");
//   }
// );
// router.get("/user/:id", (req, res, next) => {
//   console.log(req.params.id);
//   res.send("regular page2");
// });
// app.use("/", router);

// const router = express.Router();
// router.use((req, res, next) => {
//   if (!req.headers["x-auth"]) return next("router");
//   next();
// });
// router.use((req, res, next) => {
//   if (!req.headers["xa-auth"]) {
//     res.status(401).send({ error: "Unauthorized", code: 401 });
//     return;
//   }
//   next();
// });
// router.get("/user/:id", (req, res) => {
//   res.send("hello, user!");
// });
// app.use("/admin", router, (req, res) => {
//   // res.sendStatus(401);
//   res.send("hello, admin!");
// });
// app.use("/", router);

app.listen(port, () => {
  console.log(`Server running on port ${port}`);
});
